package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.aspect.LogRecord;
import com.woniuxy.dao.CarRepairMapper;
import com.woniuxy.dto.CarRepairDto;
import com.woniuxy.entity.CarRepair;
import com.woniuxy.service.CarRepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service
public class CarRepairServiceImpl implements CarRepairService {
    @Autowired
    private CarRepairMapper carRepairMapper;
    /**
     * 分页查询
     * @param condition
     * @param pageNum   当前页
     * @param pageSize  每页大小
     * @return 分页对象
     */
    @Override
    public PageInfo<CarRepairDto> findByPage(Map<String, Object> condition, int pageNum, int pageSize) {
        //设置页面大小数量
        PageHelper.startPage(pageNum, pageSize);
        //调用DAO层查询
        List<CarRepairDto> list = carRepairMapper.findAll(condition);
        return new PageInfo<>(list);
    }

    /**
     * 添加
     *
     * @param carRepair
     */
    @LogRecord
    @Override
    public int save(CarRepair carRepair) {
        return carRepairMapper.save(carRepair);
    }

    /**
     * 修改
     *
     * @param carRepair
     */
    @LogRecord
    @Override
    public int updateById(CarRepair carRepair) {
        return carRepairMapper.updateById(carRepair);
    }

    /**
     * 删除
     *
     * @param id
     */
    @LogRecord
    @Override
    public int deleteById(Integer id) {
        return carRepairMapper.deleteById(id);
    }

    /**
     * 批量删除
     *
     * @param ids
     */
    @LogRecord
    @Override
    public int deleteBatch(String[] ids) {
        return carRepairMapper.deleteBatch(ids);
    }

    /**
     * 导出所有数据Excel
     */
    @Override
    public List<CarRepairDto> findAll() {
        return carRepairMapper.findAll(null);
    }

    /**
     * 批量添加数据
     *
     * @param carRepairList
     */
    @Override
    public int insertBatch(List<CarRepairDto> carRepairList) {
        return carRepairMapper.insertBatch(carRepairList);
    }
}
